<template>
  <div class="main">
    <!-- 条件查询 -->
    <el-card class="card" shadow="never">
      <div slot="header" class="clearfix">
        <span class="condtion">条件查询</span>
      </div>
      <!-- 条件查询内容 -->
      <div>
        <el-form
          size="mini"
          :inline="true"
          :model="searchFrom"
          class="demo-form-inline"
        >
          <el-form-item label="订单编号" class="users">
            <el-input
              v-model="searchFrom.orderSn"
              placeholder="订单编号"
            ></el-input>
          </el-form-item>
          <el-form-item label="订单类型" class="users">
            <el-select
              size="mini"
              v-model="searchFrom.totalQuantity"
              placeholder="请选择"
            >
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="支付方式" class="users">
            <el-select
              size="mini"
              v-model="searchFrom.payType"
              placeholder="请选择"
            >
              <el-option
                v-for="item in optionser"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="订单状态" class="users">
            <el-select
              size="mini"
              v-model="searchFrom.status"
              placeholder="请选择"
            >
              <el-option
                v-for="item in optionsers"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <!-- 
          
          <span>
            订单状态：<el-select
              size="mini"
              v-model="searchFrom.status"
              placeholder="请选择"
            >
              <el-option
                v-for="item in optionsers"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </span> -->
          <el-form-item class="usered">
            <el-button @click="reset">重置</el-button>
            <el-button type="primary" @click="doSearch">查询</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-card>
    <!-- 文章列表table表单 -->
    <el-card shadow="never" class="card">
      <el-table
        border
        :data="tableData"
        style="width: 100%"
        max-height="1000"
        v-loading="loading"
      >
        <el-table-column label="#" fixed type="index" width="50">
        </el-table-column>
        <el-table-column
          prop="orderSn"
          label="订单编号"
          width="300"
          heigth="133"
          align="center"
        >
        </el-table-column>
        <el-table-column label="支付方式" width="180">
          <template slot-scope="scope">
            <div v-if="scope.row.payType == 0" class="non-payment">未支付</div>
            <svg
              v-if="scope.row.payType == 1"
              t="1682055977006"
              class="icon"
              viewBox="0 0 1024 1024"
              version="1.1"
              xmlns="http://www.w3.org/2000/svg"
              p-id="3443"
              id="mx_n_1682055977007"
              width="58"
              height="38"
            >
              <path
                d="M776.496511 93.672426 238.646773 93.672426c-82.171488 0-149.402705 67.232241-149.402705 149.402705l0 537.849738c0 82.171488 67.232241 149.401682 149.402705 149.401682l537.848715 0c82.171488 0 149.402705-67.230194 149.402705-149.401682l0-537.849738C925.899216 160.903643 858.666976 93.672426 776.496511 93.672426zM776.496511 870.565469 238.646773 870.565469c-49.431829 0-89.641623-40.210817-89.641623-89.6406l0-537.849738c0-49.431829 40.209794-89.642646 89.641623-89.642646l537.848715 0c49.430806 0 89.641623 40.210817 89.641623 89.642646l0 438.898075c-43.565215-30.522154-112.052029-72.863495-222.556818-117.829616 37.087687-68.484767 57.280588-128.042211 59.149145-133.585461l13.07069-37.614689L537.452183 392.94344l0-60.22771 209.162764 0 0-59.759035L537.452183 272.956695l0-89.642646c0 0-28.771277 0-43.332924 0-14.560624 0-15.96153 9.42465-15.96153 11.949146 0 2.523473 0 77.692477 0 77.692477L268.528338 272.955672l0 59.759035 209.629391 0 0 60.22771L298.407855 392.942417l0 59.294454 332.85797 0c-11.263531 27.458375-26.583448 59.2218-45.288462 92.561116-78.042447-24.031323-171.69543-38.956244-235.089249-31.326473-64.167438 7.674796-112.198362 39.875173-131.777279 88.343047-17.056468 42.25436-9.367345 90.925872 20.060895 127.020952 27.970028 34.287921 70.513984 52.553936 120.179127 52.553936 12.94073 0 26.378787-1.223874 40.151465-3.765767 83.425038-15.288195 164.998915-86.896092 213.117842-161.160493 126.524648 43.682895 219.902362 112.13901 253.516948 134.578068l0 29.882588C866.137111 830.354652 825.926294 870.565469 776.496511 870.565469zM553.501718 597.234243c-40.910759 59.616796-107.149369 111.060445-164.766624 121.624035-44.601824 8.081049-82.201164-1.955538-103.253642-27.809369-15.654538-19.200294-19.857257-44.819788-10.957563-66.851571 11.337209-28.070312 40.969087-46.309722 83.455737-51.386344 9.425673-1.136893 19.288299-1.663896 29.515221-1.663896C432.665629 571.147098 500.028852 581.535703 553.501718 597.234243z"
                fill="#ffffff"
                p-id="3444"
              ></path>
            </svg>
            <el-button
              v-if="scope.row.payType == 2"
              type="success"
              icon="el-icon-chat-dot-round"
            ></el-button>
          </template>
        </el-table-column>
        <el-table-column label="订单状态" width="150">
          <template slot-scope="scope">
            <div v-if="scope.row.status == 0" class="obligation">代付款</div>
            <div v-if="scope.row.status == 1" class="returns">代发货</div>
            <div v-if="scope.row.status == 2" class="completed">已发货</div>
            <div v-if="scope.row.status == 3" class="frame">已完成</div>
            <div v-if="scope.row.status == 4" class="framees">退货了</div>
            <div v-if="scope.row.status == 5" class="invalid">无效订单</div>
          </template>
        </el-table-column>
        <el-table-column
          prop="createTime"
          label="添加时间"
          width="200"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="memberUsername"
          label="用户账号"
          width="200"
          align="center"
        >
        </el-table-column>
        <el-table-column label="订单类型" width="200" align="center">
          <template slot-scope="scope">
            <div v-if="scope.row.orderType == 0">秒杀订单</div>
            <div v-else>正常订单</div>
          </template>
        </el-table-column>
        <el-table-column label="备注" width="150" align="center">
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="120" align="center">
          <template slot-scope="scope">
            <el-button @click="resetes(scope.row.id)" type="primary"
              >产看订单</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <!-- 分页 -->
    <el-pagination
      :current-page="page.currentPage"
      :page-sizes="page.pageSizes"
      :page-size="page.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="page.total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    >
    </el-pagination>
  </div>
</template>

<script>
import orderFor from '@/api/orderFor.js'
import mixin from '@/mixins'

export default {
  mixins: [mixin],
  data() {
    return {
      searchFrom: {}, //输入框里的对象
      form: {}, //实际搜索要用的表单
      tableData: [], //文章列表数据
      loading: false,
      value: '',
      options: [
        {
          label: '正常订单',
          value: '0',
        },
        {
          label: '秒杀订单',
          value: '1',
        },
      ],
      optionser: [
        {
          label: '未支付',
          value: '0',
        },
        {
          label: '支付宝',
          value: '1',
        },
        {
          label: '微信',
          value: '2',
        },
      ],
      optionsers: [
        {
          label: '代付款',
          value: '0',
        },
        {
          label: '待发货',
          value: '1',
        },
        {
          label: '已发货',
          value: '2',
        },
        {
          label: '已完成',
          value: '3',
        },
        {
          label: '退货',
          value: '4',
        },
        {
          label: '无效订单',
          value: '5',
        },
      ],
    }
  },
  created() {
    this.findOrdersByPage()
  },
  mounted() {},
  methods: {
    //获取文章列表
    findOrdersByPage() {
      this.loading = true
      setTimeout(() => {
        orderFor
          .findOrdersByPageApi(
            this.page.currentPage,
            this.page.pageSize,
            this.from
          )
          .then(res => {
            console.log(res, 'res')
            if (res.success) {
              this.tableData = res.data.rows //获取到线上文字地址
              this.page.total = res.data.total //获取文章总条数
            } else {
              this.$message.error('请求失败')
            }
            console.log(this.tableData, 'this.tableData')
            this.loading = false
          })
      })
    },
    //每页多少条 改变时触发事件
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      this.page.pageSize = val
      this.findOrdersByPage()
    },
    //修改页触发的事件
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      this.page.currentPage = val
      this.findOrdersByPage()
    },
    //查看订单
    resetes(row) {
      console.log(row, '查看订单')

      this.$router.push({ name: 'Detaile', params: { id: row } })
    },
    //查询
    doSearch() {
      this.page = {
        currentPage: 1, //当前页
        pageSizes: [10, 20, 30, 40],
        pageSize: 10, //每页多少条数据
        total: 0, //总数据条数
      }
      this.from = Object.assign({}, this.searchFrom)
      this.findOrdersByPage()
      console.log(this.searchFrom, 'this.searchFrom')
      console.log(this.from, 'this.from')
    },
    //重置
    reset() {
      this.searchFrom = {}
      this.page = {
        currentPage: 1, //当前页
        pageSizes: [10, 20, 30, 40],
        pageSize: 10, //每页多少条数据
        total: 0, //总数据条数
      }
      this.findOrdersByPage()
    },
  },
}
</script>

<style lang="scss" scoped>
.main {
  background: #f5f5f5;
  .card {
    width: 96.5%;
    margin: 30px;
  }
}

.users {
  margin-right: 100px;
}
.usered {
  position: relative;
  top: 30px;
}
.el-card__body {
  height: 1200px;
}
.obligation {
  background-color: #f56c6c;
  color: #fff;
  width: fit-content;
  border-radius: 3px;
  padding: 3px;
}
.returns {
  background-color: #e6a23c;
  color: #fff;
  width: fit-content;
  border-radius: 3px;
  padding: 3px;
}
.completed {
  background-color: #ecf5ff;
  color: #50a5ff;
  width: fit-content;
  border-radius: 3px;
  padding: 3px;
}
.frame {
  background-color: #409eff;
  color: #fff;
  width: fit-content;
  border-radius: 3px;
  padding: 3px;
}
.framees {
  background-color: #909399;
  color: #fff;
  width: fit-content;
  border-radius: 3px;
  padding: 3px;
}
.invalid {
  background-color: #f4f4f5;
  color: #909399;
  width: fit-content;
  border-radius: 3px;
  padding: 3px;
}
.non-payment {
  background-color: #909399;
  color: #fff;
  width: fit-content;
  border-radius: 3px;
  padding: 3px;
}
.icon {
  background-color: #409eff;
  color: #fff;
  width: fit-content;
  border-radius: 3px;
  padding: 3px;
}
</style>